+2007-11-11 Øyvind Kolås <pippin@gimp.org>
+
+ Keep a cache of the linear version of BablImage's needed for
+ BablFormats around. This reduces the constant overhead for
+ conversions.
+
+ * babl/babl-classes.h: added .image_template field to BablFormat.
+ * babl/babl-format.c: (format_new): make .image_template NULL by
+ defualt.
+ * babl/babl-image.c: (babl_image_from_linear): use .image_template if
+ available instead of creating our own BablImage from scratch.
+ * babl/babl-memory.c: (babl_free): special case freeing of BablImage
+ and BablFormat to do the extra juggling needed for the image_template
+ cache.
+
2007-11-10 Øyvind Kolås <pippin@gimp.org>
* babl/babl-fish-stats.c: (table_destination_each): improve
int components;
BablComponent **component;
BablType **type;
+ void *image_template; /* image template for use with
+ linear (non-planer) images */
+
BablSampling **sampling;
BablModel *model;
int bytes_per_pixel;
BablModel *model; /*< (always known) */
int components;
BablComponent **component;
- BablSampling **sampling;
BablType **type;
+ BablSampling **sampling;
char **data;
int *pitch;
int *stride;
}
babl->format.loss = -1.0;
+ babl->format.image_template = NULL;
return babl;
}
switch (format->class_type)
{
case BABL_FORMAT:
- model = (BablModel *) format->format.model;
components = format->format.components;
+ if (format->format.image_template != NULL) /* single item cache for speeding
+ up subsequent use of linear buffers
+ for subsequent accesses
+ */
+ {
+ babl = format->format.image_template;
+ format->format.image_template = NULL;
+ for (i = 0; i < components; i++)
+ {
+ babl->image.data[i] = buffer + offset;
+ offset += (format->format.type[i]->bits / 8);
+ }
+ return babl;
+ }
+ model = (BablModel *) format->format.model;
memcpy (component, format->format.component, sizeof (Babl *) * components);
memcpy (sampling, format->format.sampling, sizeof (Babl *) * components);
}
babl = image_new (
- (BablFormat *) format,
+ (BablFormat *) format!=model?format:NULL,
model, components,
component, sampling, type, data, pitch, stride);
return babl;
babl_free (void *ptr,
...)
{
+ /* XXX:
+ * Extra logic to make the bookeeping of BablImage cached
+ * templates work out correctly, by using a babl_image_destroy
+ * and custom destroy functions for babl_format this would be
+ * avoided and the extra overhead not needed for non image/format
+ * typed allocations.
+ */
+ if (BABL_IS_BABL (ptr))
+ {
+ switch (BABL (ptr)->instance.class_type)
+ {
+ case BABL_IMAGE:
+ {
+ BablFormat *format = BABL(ptr)->image.format;
+ if (format)
+ {
+ if (format->image_template == NULL)
+ {
+ format->image_template = ptr;
+ return;
+ }
+ else
+ {
+ }
+ }
+ }
+ break;
+ case BABL_FORMAT:
+ {
+ BablFormat *format = ptr;
+ if (format->image_template != NULL)
+ {
+ BAI (format->image_template)->signature = NULL;
+ free_f (BAI (format->image_template));
+ frees++;
+ }
+ format->image_template = NULL;
+ }
+ break;
+ default:
+ break;
+ }
+ }
if (!ptr)
return;
if (!IS_BAI (ptr))